package com.shujia.jinjie;

import com.shujia.utils.MySQLTool;
import com.shujia.utils.RedisTool;
import redis.clients.jedis.JedisCluster;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class IndexData {
    public static void main(String[] args) throws Exception {
        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);

        //从mysql中获取华为或者联想数据的id值存储到redis中
        Connection conn = MySQLTool.getConnection();

        //创建与redis的连接对象
        JedisCluster jedisCluster = RedisTool.getConnection();

        PreparedStatement prepareStatement = conn.prepareStatement("select id from jd_goods where goods_name like ?");

        System.out.println("请输入要构建二级索引的商品品牌：");
        String pinPai = sc.next();

        prepareStatement.setString(1, "%" + pinPai + "%");

        ResultSet resultSet = prepareStatement.executeQuery();

        while (resultSet.next()){
            String id = resultSet.getString(1);
//            System.out.println(id);
            jedisCluster.sadd("pinPai:"+pinPai, id);
        }

        prepareStatement.close();
        jedisCluster.close();
        conn.close();

    }
}
